import os
import pandas as pd

dsex={'0':'女','1':'男'}
dpro={'bj':'北京','sh':'上海','tj':'天津','cq':'重庆',
      'hlj':'黑龙江','ln':'辽宁','jl':'吉林','hb':'河北','hn':'河南',
      'sd':'山东','sx':'山西','ah':'安徽','zj':'浙江','js':'江苏',
      'fj':'福建','gd':'广东','sc':'四川','yn':'云南','gz':'贵州',
      'qh':'青海','gs':'甘肃','jx':'江西','tw':'台湾'}
df2 = pd.DataFrame()
dirlist=[x for x in os.listdir() if os.path.isdir(x)]
for d in dirlist:
    #name=os.listdir(d)
    liston=[]
    
    name=[x for x in os.listdir(d) if os.path.isfile(os.path.join(d,x))]
    #print(os.path.abspath('.'))
    try:
        onename=name[0]
        onename=onename.split('_')
        try:
            addr=onename[1]
            try:
                addr=dpro[addr]
            except:
                pass
            sex=onename[2]
            sex=dsex[sex]
            age=onename[3]
        except:
            print('wrong name ')
        liston.append(addr)
        liston.append(sex)
        liston.append(age)
        #print(liston)
        df2[d]=liston
    except:
        print('empty %s'%d)
    
	
    
df2=df2.T
        
def main():
    
    
    
    #df2['姓名2']=['籍贯','性别','年龄']
    
    print(df2)
    df2.to_excel('表格.xls')
    
    print('done')
    os.system('pause')
if __name__ == '__main__':
	main()
